﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace TwainLib
{
    public class DeviceSource
    {
        internal DeviceSource(DeviceSourceManager deviceSourceManager, TwIdentity id)
        {
            this.deviceSourceManager = deviceSourceManager;
            this.id = id;
        }

        public bool Open()
        {
            return deviceSourceManager.OpenDS(this);
        }

        public void Close()
        {
            deviceSourceManager.CloseDS(this);
        }

        public DeviceSourceCapability GetCapability(TwCap capIndex)
        {
            DeviceSourceCapability capability = new DeviceSourceCapability(this, capIndex);
            deviceSourceManager.GetCapability(capability);
            return capability;
        }

        public void ShowAllCapabilities()
        {
            TwCap[] caps = (TwCap[])Enum.GetValues(typeof(TwCap));
            for (int i = 0; i < caps.Length; i++)
            {
                DeviceSourceCapability capability = new DeviceSourceCapability(this, caps[i]);
                deviceSourceManager.GetCapability(capability);
                //if (capability.CanSupported)
                    Debug.WriteLine(capability.ToString());
            }
        }

        public void ShowAllCapabilitiesHelp()
        {
            TwCap[] caps = (TwCap[])Enum.GetValues(typeof(TwCap));
            for (int i = 0; i < caps.Length; i++)
            {
                DeviceSourceCapability capability = new DeviceSourceCapability(this, caps[i]);
                deviceSourceManager.GetCapabilityHelp(capability);
                //if (capability.CanSupported)
                //Debug.WriteLine(capability.ToString());
            }
        }

        public void ShowAllCapabilitiesLabel()
        {
            TwCap[] caps = (TwCap[])Enum.GetValues(typeof(TwCap));
            for (int i = 0; i < caps.Length; i++)
            {
                DeviceSourceCapability capability = new DeviceSourceCapability(this, caps[i]);
                deviceSourceManager.GetCapabilityLabel(capability);
                //if (capability.CanSupported)
                //Debug.WriteLine(capability.ToString());
            }
        }

        internal bool SetCapability(DeviceSourceCapability cap)
        {
            
            deviceSourceManager.SetCapability(cap);
            return true;
        }

        private TwIdentity id;
        private DeviceSourceManager deviceSourceManager;
        public DeviceSourceManager DeviceSourceManager
        {
            get
            {
                return deviceSourceManager;
            }
        }
        
        internal TwIdentity Id
        {
            get { return id; }
            set { id = value; }
        }
        
    }
}
